from collections import defaultdict


class Solution:
    def countAndSay(self, n: int) -> str:
        i = 1
        count_dict = defaultdict(int)
        now = "1"

        while i<n:
            apper_list = ""
            if len(now)>0:
                flag = now[0]
            cc = 0
            for j in now:

                if j == flag:
                    count_dict[j] +=1
                    print(count_dict)
                    cc+=1
                    if cc == len(now):
                        apper_list += (str(count_dict[flag]) + flag)
                else:
                    apper_list += (str(count_dict[flag]) + flag)
                    flag = j
                    count_dict[j] =1
                    cc += 1
                    if cc == len(now):
                        apper_list += (str(count_dict[flag]) + flag)
           # print(now)
            count_dict.clear()
            now = apper_list
            print(now)
            i+=1
        return now


if __name__ == '__main__':
    n = 5
    solution = Solution()
    val = solution.countAndSay(n)
    print(val)